<template>
  <div class="app-container">
    <el-row>
      <!-- 顶部搜索栏 -->
      <el-form ref="queryForm" :model="queryParams" v-show="showSearch" :inline="true">
        <el-form-item label="标签打印日期">
          <el-date-picker
            v-model="dateRange"
            size="small"
            style="width: 240px"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="班组" prop="team">
          <el-select v-model="queryParams.team" placeholder="请选择班组" clearable :style="{width: '100%'}">
            <el-option v-for="(item, index) in teamOptions" :key="index" :label="item.label" :value="item.value"
                       :disabled="item.disabled"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="产线" prop="areaID">
          <el-select v-model="queryParams.areaID" placeholder="请选择产线" clearable :style="{width: '100%'}">
            <el-option v-for="(item, index) in areaIDOptions" :key="index" :label="item.label" :value="item.value"
                       :disabled="item.disabled"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="工号" prop="winderName">
          <el-input v-model="queryParams.winderName" placeholder="请输入工号" clearable  style="width: 200px">
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <!-- 表头按钮组 -->
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            size="mini"
            @click="handleSave"
          >复打</el-button>
        </el-col>

        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
      </el-row>


      <!-- 后台回显表格 -->
      <el-table v-loading="loading" :data="pellList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="50" fixed="left" align="center" />
        <el-table-column label="产线" width="80" fixed="left" align="center" key="areaID" prop="areaID" v-if="columns[0].visible"  />
        <el-table-column label="产品名称" align="center" fixed="left" key="defName" prop="defName" width="200" v-if="columns[1].visible" :show-overflow-tooltip="true" />
        <el-table-column label="定重" align="center" prop="gy_dz" width="70" v-if="columns[2].visible" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <el-input v-model="scope.row.gy_dz"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="班组" align="center" prop="team" width="50" v-if="columns[3].visible" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <p v-if="scope.row.team=='1'">甲班</p>
            <p v-if="scope.row.team=='2'">乙班</p>
            <p v-if="scope.row.team=='3'">丙班</p>
          </template>
        </el-table-column>
        <el-table-column label="工号" align="center" width="50" key="winderName" prop="winderName" v-if="columns[4].visible" :show-overflow-tooltip="true" />
        <el-table-column label="底部描述是否打印" width="75" align="center" prop="is_bottom" v-if="columns[5].visible" >
          <template slot-scope="scope">
            <p v-if="scope.row.is_bottom=='0'">不打印</p>
            <p v-if="scope.row.is_bottom=='1'">打印</p>
          </template>
        </el-table-column>
        <el-table-column label="定重是否打印" width="75" align="center"  prop="is_dz" v-if="columns[6].visible">
          <template slot-scope="scope">
            <p v-if="scope.row.is_dz=='0'">不打印</p>
            <p v-if="scope.row.is_dz=='1'">打印</p>
          </template>
        </el-table-column>
        <el-table-column label="顺逆区分" align="center" width="75" prop="is_sn" v-if="columns[7].visible">
          <template slot-scope="scope">
            <p v-if="scope.row.is_sn=='0'">不打印</p>
            <p v-if="scope.row.is_sn=='1'">顺时针</p>
            <p v-if="scope.row.is_sn=='2'">逆时针</p>
          </template>
        </el-table-column>
        <el-table-column label="日期方式" align="center" prop="is_date" v-if="columns[8].visible" width="110">
          <template slot-scope="scope">
            <p v-if="scope.row.is_date=='0'">不打印</p>
            <p v-if="scope.row.is_date=='1'">格式:年-月-日</p>
            <p v-if="scope.row.is_date=='2'">格式:日-月-年</p>
          </template>
        </el-table-column>
        <el-table-column label="打印张数" align="center" prop="printcount" v-if="columns[9].visible" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <el-input v-model="scope.row.printcount"></el-input>
          </template>
        </el-table-column>

        <el-table-column label="打印日期" align="center" prop="printdate" v-if="columns[10].visible" width="160">
          <template slot-scope="scope">
            <el-date-picker
              v-model="scope.row.printdate"
              type="date"
              value-format="yyyy-MM-dd"
              size="small"
              placeholder="选择日期">
            </el-date-picker>
          </template>
        </el-table-column>
        <el-table-column label="打印人" align="center" prop="printUser" v-if="columns[11].visible" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            {{ scope.row.users[0].nickName }}
          </template>
        </el-table-column>

        <el-table-column
          label="操作"
          align="center"
          width="80"
          fixed="right"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope" v-if="scope.row.productId !== 1">
            <el-button
              size="mini"
              type="text"
              @click="handleSave(scope.row)"
            >复打</el-button>
          </template>
        </el-table-column>

      </el-table>

      <!-- 底部pagination -->
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-row>
  </div>
</template>

<script>
import { putList ,savePut } from '@/api/wind/list/list'

export default {
  name: 'List',
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 非单个禁用
      single: true,
      //选中数组
      busPellList:[],
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      //络纱标签数据
      pellList: null,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        areaID: undefined,
        team:undefined,
        winderName:undefined,
        printdate:undefined
      },
      // 列信息
      columns: [
        { key: 0, label: `产线`, visible: true },
        { key: 1, label: `产品名称`, visible: true },
        { key: 2, label: `定重`, visible: true },
        { key: 3, label: `班组`, visible: true },
        { key: 4, label: `工号`, visible: true },
        { key: 5, label: `底部描述是否打印`, visible: true },
        { key: 6, label: `定重是否打印`, visible: true },
        { key: 7, label: `顺逆区分`, visible: true },
        { key: 8, label: `日期方式`, visible: true  },
        { key: 9, label: `打印张数`, visible: true  },
        { key: 10, label: `打印时间`, visible: true  },
        { key: 11, label: `打印人`, visible: true  },
      ],
      areaIDOptions: [{
        "label": "304",
        "value": "0101304"
      }, {
        "label": "307",
        "value": "0101307"
      }],
      teamOptions: [{
        "label": "甲班",
        "value": "1"
      }, {
        "label": "乙班",
        "value": "2"
      }, {"label": "丙班",
        "value": "3"
      }]
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询产品列表 */
    getList() {
      this.loading = true;
      putList(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.pellList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 多选框选中数据 **/
    handleSelectionChange(selection) {
      this.busPellList = selection.map(item => item);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    /** 保存按钮操作 */
    handleSave(row) {
      let list = [];
      if(row.guid){
        list.push(row);
      } else {
        list = this.busPellList;
      }

      let formData = new FormData();
      formData.append("list", JSON.stringify(list));
      savePut(formData).then(response => {
        this.msgSuccess("添加成功");
      });
    },
  }
}
</script>

<style scoped>

</style>
